﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EShop.DataAccess;
using fastJSON;
using EShop.BussinessObjects;
using Mabna.Total.BOHelper;
using EShop.Common;
using EShop.BusinessLogic;
using DbLinq.Data.Linq;

public partial class Galleries : BaseThemePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            CompanyGallery companyGallery_Filter = new CompanyGallery();
            companyGallery_Filter.ID = (int)cnstDatabase.DBOperationResult.ValueIsNotEffective;
            companyGallery_Filter.Company = new Company();
            companyGallery_Filter.Company.ID = CGlobalData.GetCurrentCompanyID();
            List<CompanyGallery> companyGalleryList = CDACompanyGallery.Select(companyGallery_Filter);
            
            foreach (CompanyGallery companyGallery in companyGalleryList)
            {
                divGalleryList.InnerHtml += "<div class='gallery_Div' onclick='ShowGallery(" + companyGallery.ID.ToString() + ");' ><span class='gallery_Menu'>" + companyGallery.Name + "</span></div>";
            }

            if (companyGalleryList.Count > 0)
            {
                int galleryID;
                if (Request.QueryString["galleryID"] != null)
                    galleryID = Convert.ToInt32(Request.QueryString["galleryID"]);
                else
                    galleryID = companyGalleryList.First().ID;

                CompanyGalleryItem companyGalleryItem_Filter = new CompanyGalleryItem();
                companyGalleryItem_Filter.ID = (int)cnstDatabase.DBOperationResult.ValueIsNotEffective;
                companyGalleryItem_Filter.CompanyGallery = new CompanyGallery();
                companyGalleryItem_Filter.CompanyGallery.ID = galleryID;
                List<CompanyGalleryItem> companyGalleryItemList = CDACompanyGalleryItem.Select(companyGalleryItem_Filter);

                foreach (CompanyGalleryItem companyGalleryItem in companyGalleryItemList)
                {
                    if (companyGalleryItem.Ref.Substring(0, 4) != "http")
                        companyGalleryItem.Ref = "App_Themes/" + Page.Theme + "/images/Gallery/" + companyGalleryItem.Ref;
                    if (companyGalleryItem.ThumbRef.Substring(0, 4) != "http")
                        companyGalleryItem.ThumbRef = "App_Themes/" + Page.Theme + "/images/Gallery/" + companyGalleryItem.ThumbRef;
                    divGallerySlideShow.InnerHtml += "<a href='" + companyGalleryItem.Ref + "'><img src='" + companyGalleryItem.ThumbRef + "' alt='" + companyGalleryItem.Caption + "'></a>";
                }

            }
        }

    }
}